Repository navigation
csdb: bound Pool reserve() by the bytes left to parse (huge allocation) - #7
Merged
Merged
Conversation
Pool::priv::getTransactions() and getNewWallets() reserve() as many elements as the uint32 count read from the data. A peer-supplied block (e.g. a BlockReply while syncing) with a count near 2^32 asks for tens of GB: std::bad_alloc/length_error escapes the transport thread and the node terminates. Reserve at most the number of bytes still unread, because every element takes at least one of them. For valid data this reserves exactly what it did before. For forged data the parse loop fails at the first missing element, as it already did, and the pool is invalid. The other counts in Pool parsing are uint8, so they are left as they are. Tests (tests/csnode/pool_tests.cpp): - Pool.HugeTransactionsCountDoesNotAllocate: before the fix from_binary throws. - Pool.HugeNewWalletsCountDoesNotAllocate: before the fix from_binary throws. nodetests: 116/116 pass. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
EnzinoBB
added a commit
that referenced
this pull request
Nov 5, 2026
- setup-test: "tokens node" passes --node-key too. The wallet no longer takes the node's key from the current folder (wallet PR #7), and this wallet.toml says node_key = "off" (the answer was create), so "node" did not resolve and the {"error": ...} JSON ended in KeyError 'source'. The error is now asserted first. - setup.ps1: the command printed for later quotes only the arguments that need it (".\credits-wallet.exe --config wallet.toml account new main"), as setup.sh does; the test looks for "account new main". - both: the create option says the account is under the wallet password, one for every account, chosen with the first (wallet PRs #9/#10). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem: huge allocations decided by received data
Pool::priv::getTransactions()andgetNewWallets()reserve()as many elements as theuint32count read from the data. A peer-supplied block (e.g. aBlockReplywhile syncing) with a count near 2^32 asks for tens of GB.std::bad_alloc/length_errorescapes the transport thread and the node terminates.Fix (
csdb/src/pool.cpp, +4/-2)Reserve at most the number of bytes still unread, because every element takes at least one of them.
Poolis invalid.The other counts in
Poolparsing areuint8and were left as they are.Tests (
tests/csnode/pool_tests.cpp)Pool.HugeTransactionsCountDoesNotAllocatefrom_binarythrowsPool.HugeNewWalletsCountDoesNotAllocatefrom_binarythrowsnodetestsUpstream
A single commit that applies to upstream. It touches
pool.cppin different places from PR #5, so the two apply without conflicts.🤖 Generated with Claude Code